//
//  BasePack.swift
//  GeneralNetworkTool
//
//  Created by Jin on 2018/5/23.
//  Copyright © 2018年 Jin. All rights reserved.
//

import Foundation

struct BaseRequestHeader:Codable {
    
    enum TerminalType : Int,Codable {
        case one = 1
        case two = 2
    }
    
    var requestCode:String?
    var terminalType:TerminalType
    var sessionId:String?
    
    func encode(to encoder:Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encodeIfPresent(requestCode, forKey: .requestCode)
        try container.encode(terminalType, forKey: .terminalType)
        try container.encodeIfPresent(sessionId, forKey: .sessionId)
    }
}


class BaseRequest:Codable {
    
    var requestParam:BaseRequestHeader?
    
    func encode(to encoder:Encoder) throws {
        var container = encoder.container(keyedBy: BaseRequest.CodingKeys.self)
        try container.encodeIfPresent(requestParam, forKey: .requestParam)
    }
    
    func signFromRequestParam(requestParam:BaseRequestHeader,data:Data) -> String {
        return "token^5LandiApp|\(requestParam)|\(data)".md5
    }
}


class BaseResponseState:Codable {
    var code:String
    var codeDesc:String
    
    private enum CodingKeys:String,CodingKey {
        case code
        case codeDesc = "description"
    }
    
    required init(from decoder:Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        code = try container.decode(String.self, forKey: .code)
        codeDesc = try container.decode(String.self, forKey: .codeDesc)
    }
    
    init(code:String,codeDesc:String) {
        self.code = code
        self.codeDesc = codeDesc
    }
}

class BasePaging:Codable {
    
}


class BaseResponse:Codable {
    let responseState:BaseResponseState
    let pagingInfo:BasePaging
    
    init(responseState:BaseResponseState,pagingInfo:BasePaging) {
        self.responseState = responseState
        self.pagingInfo = pagingInfo
    }
}




